package org.chengyi.model_shop.controller;

import org.chengyi.model_shop.entity.AdminOrderDetailDTO;
import org.chengyi.model_shop.entity.Order;
import org.chengyi.model_shop.entity.OrderDetailDTO;
import org.chengyi.model_shop.service.OrderService;
import org.chengyi.model_shop.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/addOrder")
    public String addOrder(@RequestBody Order order){
        return orderService.addOrder(order);
    }
    @GetMapping("/getOrderItemList")
    public List<OrderDetailDTO> getOrderItemList(){
        Integer userId = ThreadLocalUtil.get();
        return orderService.selectOrderItmByUserId(userId);
    }
    
    @PutMapping("/orders/{orderId}/ship")
    public String shipOrder(@PathVariable Integer orderId) {
        return orderService.shipOrder(orderId);
    }
    
    @GetMapping("/admin/orders")
    public List<AdminOrderDetailDTO> getAllAdminOrders() {
        return orderService.getAllAdminOrders();
    }
    @GetMapping("/admin/userOrder")
    public List<AdminOrderDetailDTO> getOrderListByUserName(@RequestParam String username) {
        System.out.println( username);
        return orderService.getOrderListByUserName(username);
    }
}
